// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MF_PHASE_SCHED_DETAIL_MFN_M07 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 CM1",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.False, HL7Required.True,"CM1")]
	    public CM1 CM1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 CM2",11)]
  	    [HL7Field(HL7Version.v23, 11, HL7Repeat.True, HL7Required.False,"CM2")]
	    public CM2[] CM2 {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			CM1 = PopSegmentParseAndCheckRequired<CM1>(availableData, options, "CM1");
			CM2 = PopSegmentParseAndCheckRequiredArray<CM2>(availableData, options, "CM2");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isCM1 = availableData.StartsWith("CM1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CM1", options.Version) || isCM1) {
				return isCM1;
			}
			bool isCM2 = availableData.StartsWith("CM2", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CM2", options.Version) || isCM2) {
				return isCM2;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MF_PHASE_SCHED_DETAIL";
			}
        }

        static MF_PHASE_SCHED_DETAIL_MFN_M07() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MF_PHASE_SCHED_DETAIL_MFN_M07));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (CM1 != null) {
			string segmentValue = CM1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CM2 != null && CM2.Length > 0) {
			for (int i = 0; i < CM2.Length; i++) {
				string segmentValue = CM2[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

